package com.grm.common;

import lombok.AllArgsConstructor;
import lombok.Data;

@Data
@AllArgsConstructor
public class Result {
    private int code;
    private String message;
    private Object data;
    private Long total;

    private static final int SUCCESS_CODE = 200;
    private static final int DEFAULT_ERROR_CODE = 500;

    private static final String DEFAULT_SUCCESS_MESSAGE = "成功！";

    public static Result success(){
        return new Result(SUCCESS_CODE,DEFAULT_SUCCESS_MESSAGE,null,null);
    }

    public static Result success(Object data){
        return new Result(SUCCESS_CODE,DEFAULT_SUCCESS_MESSAGE,data,null);
    }

    public static Result success(Object data,Long total){
        return new Result(SUCCESS_CODE,DEFAULT_SUCCESS_MESSAGE,data,total);
    }

    public static Result failed(String message){
        return new Result(DEFAULT_ERROR_CODE,message,null,null);
    }

    public static Result failed(int code,String message){
        return new Result(code,message,null,null);
    }
}
